package org.cosmact.designer.vxml.gefeditor.uiresources;

import org.cosmact.designer.vxml.gefeditor.VxmlGefEditorPlugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Image;

/**
 * Manage resource like images, icons, fonts and colors used in applications
 * 
 *@author YeXiaowei 234aini@gmail.com
 * 
 */
public class UIResource {

	public static ImageDescriptor getImageDescriptor(EIcons icon) {
		ImageRegistry imageRegistry = JFaceResources.getImageRegistry();
		String key = icon.getIconFile();
		ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = ImageDescriptor.createFromFile(
					VxmlGefEditorPlugin.class, key);

			if (imageRegistry.get(key) == null) {
				imageRegistry.put(key, imageDescriptor.createImage());
			}

			if (imageRegistry.getDescriptor(key) == null)
				imageRegistry.put(key, imageDescriptor);

		}
		return imageDescriptor;
	}

	public static Image getImage(EIcons icon) {
		return getImageDescriptor(icon).createImage();
	}
}
